package org.web.hello.dubbomarket.server.biz.impl;

import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.web.base.domain.ResultDO;
import org.web.base.domain.helper.ResultHelper;
import org.web.base.domain.helper.ServiceExceptionHelper;
import org.web.base.domain.helper.ValidationHelper;
import org.web.base.helper.BeanConvertHelper;
import org.web.hello.dubbomarket.sdk.biz.AccountInfoBiz;
import org.web.hello.dubbomarket.sdk.dto.AccountInfoDTO;
import org.web.hello.dubbomarket.sdk.dto.query.QueryAccountInfoRequest;
import org.web.hello.dubbomarket.sdk.dto.query.QueryUserDTO;
import org.web.hello.dubbomarket.server.domain.AccountInfoDO;
import org.web.hello.dubbomarket.server.domain.query.QueryAccountInfo;
import org.web.hello.dubbomarket.server.service.AccountInfoService;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service("accountInfoBiz")
@DubboService(interfaceClass = org.web.hello.dubbomarket.sdk.biz.AccountInfoBiz.class)
public class AccountInfoBizImpl implements AccountInfoBiz {

    @Resource
    private AccountInfoService accountInfoService;

    @Override
    @DubboService()
    public ResultDO<List<AccountInfoDTO>> selectAclResourceList(QueryAccountInfoRequest queryAccountInfoRequest) {
        ResultDO<List<AccountInfoDTO>> resultDO = new ResultDO<>();
        try {
            // 查询对象校验, 如果调用BIZ层方法，则无需校验，因为BIZ自会进行校验。
            ValidationHelper.validateWithThrow(QueryAccountInfoRequest.class, queryAccountInfoRequest);
            QueryAccountInfo queryAccountInfo = new QueryAccountInfo();
            BeanUtils.copyProperties(queryAccountInfoRequest, queryAccountInfo);
            List<AccountInfoDO> accountInfoList = accountInfoService.selectAccountInfoList(queryAccountInfo);
            List<AccountInfoDTO> accountInfoDTOList = BeanConvertHelper.convertListToList(accountInfoList, AccountInfoDTO.class);
            resultDO.setDomain(accountInfoDTOList);
        } catch (Exception e) {
            resultDO = ResultHelper.buildResultDOByException(e);
        }
        return resultDO;
    }
}